home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5438 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  54 lines

  1. Path: taco.cc.ncsu.edu!bwmott
  2. From: bwmott@unity.ncsu.edu (Bradford Wayne Mott)
  3. Newsgroups: comp.lang.c++
  4. Subject: Virtual member functions and forward declaration
  5. Date: 4 Feb 1996 18:44:40 GMT
  6. Organization: North Carolina State University
  7. Message-ID: <4f2uqo$pq4@taco.cc.ncsu.edu>
  8. NNTP-Posting-Host: pythagoras.csc.ncsu.edu
  9. Keywords: virtual, member, function, g++
  10.  
  11. I've got a question about forward declarations and virtual functions.  My
  12. class layout is similar to the following:
  13.  
  14. class S;
  15. class T;
  16.  
  17. class A {
  18.   public:
  19.     virtual S& belong() = 0;
  20. };
  21.  
  22. class B : public A {
  23.   public:
  24.     virtual T& belong() { return myT; }  // This doesn't work 
  25.   private:
  26.     T& myT;
  27. };
  28.  
  29.  
  30. class S {
  31.   public:
  32.     virtual A& get() = 0;
  33. };
  34.  
  35. class T : public S {
  36.   public:
  37.     virtual B& get() { return myB; }    // This works fine
  38.   private:
  39.     B& myB;
  40. };
  41.  
  42. The problem I'm having is that I can redeclare the return type in one
  43. of the class layouts (S,T) however I can't do it in both because when 
  44. the virtual member function [T& belong() in class B] is declared the
  45. compiler doesn't know that T is a subclass of S.
  46.  
  47. Is there anyway to do this? 
  48.  
  49. Thanks,
  50. Bradford W. Mott
  51.  
  52. P.S. I'm using g++ 2.7.2 if that makes a difference.
  53.  
  54.